using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using FAQComponents;
using FAQComponents.Objects;
using FAQComponents.API;
using Adge.UI.WebControls;

namespace Adge.Web.Faq.Admin
{
	/// <summary>
	/// Summary description for EditCategory.
	/// </summary>
	public partial class EditCategory : CategoryRepeaterPage
	{
	
		private int categoryID;
		public int ParentCategoryID;

		protected void Page_Load(object sender, System.EventArgs e)
		{
			categoryID = InvariantString.ToInt32(Request.QueryString["ID"]);
			if (!Page.IsPostBack)
			{
				Category c = CategoryAPI.GetCategory(categoryID);
				ParentCategoryID = c.ParentCategoryID;
				nameAdd.Text = c.Name;
				descriptionAdd.Text = c.Description;

				CategoryCollection csAdd = CategoryAPI.GetAllCategories();
				Category cAdd = new Category();
				cAdd.CategoryID = Globals.NULLIntegerValue;
				cAdd.GroupID = -1;
				cAdd.Name = "-- TOP-LEVEL CATEGORY --";
				cAdd.Depth = 0;
				csAdd.Insert(0, cAdd);

				rptCategoriesAdd.DataSource = csAdd;
				rptCategoriesAdd.DataBind();
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    

		}
		#endregion

		protected void btnCancel_Click(object sender, System.EventArgs e)
		{
			Response.Redirect("CategoryAdmin.aspx");
		}

		protected void btnAddCategory_Click(object sender, System.EventArgs e)
		{
			Category c = new Category();
			c.CategoryID = categoryID;
			c.Name = nameAdd.Text;
			c.Description = descriptionAdd.Text;
			c.ParentCategoryID = InvariantString.ToInt32(Request.Form["categoryAdd"]);

			CategoryAPI.UpdateCategory(c);

			Response.Redirect("CategoryAdmin.aspx");		// send the user back to the category admin page
		}
	}
}
